﻿/*
 * KLF Headless Browser
 * Written by Kris Oye <kristianoye@gmail.com>
 * Copyright (C) 2011-2012.  All rights reserved.
 */
namespace KLF.Lib.Browser.DOM.HTML
{
    #region Using Statements

    using System;

    #endregion

    /// <summary>
    /// Generic embedded object.
    /// 
    /// Note: In principle, all properties on the object element are read-write
    /// but in some environments some properties may be read-only once the 
    /// underlying object is instantiated. See the OBJECT element definition 
    /// in [HTML 4.01].
    /// </summary>
    public class HTMLObjectElement : HTMLBlockBaseElement
    {
        #region Constructors

        internal HTMLObjectElement(Document owner)
            : base(owner, "object")
        {
        }

        #endregion

        #region DOM Level 2 HTML Compliance

        /// <summary>
        /// Space-separated list of archives. See the archive attribute 
        /// definition in HTML 4.01.
        /// </summary>
        public string archive
        {
            get
            {
                return getAttribute(HTMLConstants.HTML_ATT_ARCHIVE);
            }
            set
            {
                if (String.IsNullOrEmpty(value))
                    removeAttribute(HTMLConstants.HTML_ATT_ARCHIVE);
                else
                    setAttribute(HTMLConstants.HTML_ATT_ARCHIVE, value);
            }
        }

        /// <summary>
        /// Width of border around image. See the border attribute definition
        /// in HTML 4.01. This attribute is deprecated in HTML 4.01. Note that
        /// the type of this attribute was DOMString in DOM Level 1 HTML 
        /// [DOM Level 1].
        /// </summary>
        public string border
        {
            get
            {
                return getAttribute(HTMLConstants.HTML_ATT_BORDER);
            }
            set
            {
                if (String.IsNullOrEmpty(value))
                    removeAttribute(HTMLConstants.HTML_ATT_BORDER);
                else
                    setAttribute(HTMLConstants.HTML_ATT_BORDER, value);
            }
        }

        /// <summary>
        /// Applet class file. See the code attribute for HTMLAppletElement.
        /// </summary>
        public string code
        {
            get
            {
                return getAttribute(HTMLConstants.HTML_ATT_CODE);
            }
            set
            {
                if (String.IsNullOrEmpty(value))
                    removeAttribute(HTMLConstants.HTML_ATT_CODE);
                else
                    setAttribute(HTMLConstants.HTML_ATT_CODE, value);
            }
        }

        /// <summary>
        /// Base URI [IETF RFC 2396] for classid, data, and archive attributes.
        /// See the codebase attribute definition in HTML 4.01.
        /// </summary>
        public string codeBase
        {
            get
            {
                return getAttribute(HTMLConstants.HTML_ATT_CODEBASE);
            }
            set
            {
                if (String.IsNullOrEmpty(value))
                    removeAttribute(HTMLConstants.HTML_ATT_CODEBASE);
                else
                    setAttribute(HTMLConstants.HTML_ATT_CODEBASE, value);
            }
        }

        /// <summary>
        /// Content type for data downloaded via classid attribute. See the 
        /// codetype attribute definition in HTML 4.01.
        /// </summary>
        public string codeType
        {
            get
            {
                return getAttribute(HTMLConstants.HTML_ATT_CODETYPE);
            }
            set
            {
                if (String.IsNullOrEmpty(value))
                    removeAttribute(HTMLConstants.HTML_ATT_CODETYPE);
                else
                    setAttribute(HTMLConstants.HTML_ATT_CODETYPE, value);
            }
        }

        /// <summary>
        /// The document this object contains, if there is any and it is 
        /// available, or null otherwise.
        /// </summary>
        public Document contentDocument
        {
            get
            {
                return null;
            }
        }

        /// <summary>
        /// A URI [IETF RFC 2396] specifying the location of the object's 
        /// data. See the data attribute definition in HTML 4.01.
        /// </summary>
        public string data
        {
            get
            {
                return getAttribute(HTMLConstants.HTML_ATT_DATA);
            }
            set
            {
                if (String.IsNullOrEmpty(value))
                    removeAttribute(HTMLConstants.HTML_ATT_DATA);
                else
                    setAttribute(HTMLConstants.HTML_ATT_DATA, value);
            }
        }

        /// <summary>
        /// Declare (for future reference), but do not instantiate, this 
        /// object. See the declare attribute definition in HTML 4.01.
        /// </summary>
        public bool declare
        {
            get
            {
                return getAttributeAsType<bool>(HTMLConstants.HTML_ATT_DECLARE, false);
            }
            set
            {
                setAttributeAsType<bool>(HTMLConstants.HTML_ATT_DECLARE, value);
            }
        }

        /// <summary>
        /// Returns the FORM element containing this control. Returns null
        /// if this control is not within the context of a form.
        /// </summary>
        public HTMLFormElement form
        {
            get
            {
                Node p = Parent;
                do
                {
                    if (p != null)
                    {
                        if (p is HTMLFormElement)
                            return (HTMLFormElement)p;
                        else
                            p = p.Parent;

                        if (p is Document)
                            p = null;
                    }
                }
                while (p != null);

                return null;
            }
        }

        /// <summary>
        /// Height of the image in pixels. See the height attribute definition
        /// in HTML 4.01. Note that the type of this attribute was DOMString 
        /// in DOM Level 1 HTML [DOM Level 1].
        /// </summary>
        public int height
        {
            get
            {
                return getAttributeAsType<int>(HTMLConstants.HTML_ATT_HEIGHT, 0);
            }
            set
            {
                setAttributeAsType<int>(HTMLConstants.HTML_ATT_HEIGHT, value);
            }
        }

        /// <summary>
        /// Horizontal space to the left and right of this image in pixels. 
        /// See the hspace attribute definition in HTML 4.01. This attribute 
        /// is deprecated in HTML 4.01. Note that the type of this attribute 
        /// was DOMString in DOM Level 1 HTML [DOM Level 1].
        /// </summary>
        public int hspace
        {
            get
            {
                return getAttributeAsType<int>(HTMLConstants.HTML_ATT_HSPACE, 0);
            }
            set
            {
                setAttributeAsType<int>(HTMLConstants.HTML_ATT_HSPACE, value);
            }
        }

        /// <summary>
        /// The name of the element (for backwards compatibility).
        /// </summary>
        public string name
        {
            get
            {
                return getAttribute(HTMLConstants.HTML_ATT_NAME);
            }
            set
            {
                if (String.IsNullOrEmpty(value))
                    removeAttribute(HTMLConstants.HTML_ATT_NAME);
                else
                    setAttribute(HTMLConstants.HTML_ATT_NAME, value);
            }
        }

        /// <summary>
        /// Message to render while loading the object. See the standby 
        /// attribute definition in HTML 4.01.
        /// </summary>
        public int tabIndex
        {
            get
            {
                return getAttributeAsType<int>(HTMLConstants.HTML_ATT_TABINDEX, 0);
            }
            set
            {
                setAttributeAsType<int>(HTMLConstants.HTML_ATT_TABINDEX, value);
            }
        }

        /// <summary>
        /// Message to render while loading the object. See the standby 
        /// attribute definition in HTML 4.01.
        /// </summary>
        public string standby
        {
            get
            {
                return getAttribute(HTMLConstants.HTML_ATT_STANDBY);
            }
            set
            {
                setAttribute(HTMLConstants.HTML_ATT_STANDBY, value);
            }
        }

        /// <summary>
        /// Content type for data downloaded via data attribute. See the type 
        /// attribute definition in HTML 4.01.
        /// </summary>
        public string type
        {
            get
            {
                return getAttribute(HTMLConstants.HTML_ATT_TYPE);
            }
            set
            {
                if (String.IsNullOrEmpty(value))
                    removeAttribute(HTMLConstants.HTML_ATT_TYPE);
                else
                    setAttribute(HTMLConstants.HTML_ATT_TYPE, value);
            }
        }

        /// <summary>
        /// Use client-side image map. See the usemap attribute definition
        /// in HTML 4.01.
        /// </summary>
        public string useMap
        {
            get
            {
                return getAttribute(HTMLConstants.HTML_ATT_USEMAP);
            }
            set
            {
                if (String.IsNullOrEmpty(value))
                    removeAttribute(HTMLConstants.HTML_ATT_USEMAP);
                else
                    setAttribute(HTMLConstants.HTML_ATT_USEMAP, value);
            }
        }

        /// <summary>
        /// Vertical space above and below this image in pixels. See the 
        /// vspace attribute definition in HTML 4.01. This attribute is 
        /// deprecated in HTML 4.01. Note that the type of this attribute 
        /// was "DOMString" in DOM Level 1 HTML [DOM Level 1].
        /// </summary>
        public int vspace
        {
            get
            {
                return getAttributeAsType<int>(HTMLConstants.HTML_ATT_VSPACE, 0);
            }
            set
            {
                setAttributeAsType<int>(HTMLConstants.HTML_ATT_VSPACE, value);
            }
        }

        /// <summary>
        /// Override width. See the width attribute definition in HTML 4.01.
        /// </summary>
        public string width
        {
            get
            {
                return getAttribute(HTMLConstants.HTML_ATT_WIDTH);
            }
            set
            {
                setAttribute(HTMLConstants.HTML_ATT_WIDTH, value);
            }
        }

        #endregion
    }
}
